--
-- @Author:      name
-- @DateTime:    2018-03-30 23:05:48
-- @Description: 消息的处理

local skynet = require "skynet"

local svrName = 'phz_service'

local Command = class("Command")

---------------------------------------------------------
-- Private
---------------------------------------------------------
function Command:ctor(message)
	self.msg = message	
	self.tbService = {}
	print("_________command____")
	self:register()		
end

--注册本服务里的消息
function Command:register()
	self.msg:registerSelf('add_robot',handler(self,self.addRobot))
	self.msg:registerSelf('del_robot',handler(self,self.delRobot))
	--
end

function Command:addRobot(data,players)
	print("____addRobot_____paohuzi__",data,players)
	local playerid
	local service
	for k,v in pairs(players) do 
		playerid = v.uid
		if self.tbService[playerid] then 
			self:delRobot(playerid)
		end		
		service = skynet.newservice(svrName)
		skynet.call(service, 'lua', 'start', data,v)	
		self.tbService[playerid] = service		
	end

end

function Command:delRobot(playerid)
	print("____delRobot_____paodekuai__",playerid)	
	local service = self.tbService[playerid]
	if service then
		skynet.send(service, 'lua', 'exit')
		self.tbService[playerid] = nil
	end
end


return Command